package cn.hackcloud.mutithread.juc;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

/**
 * 当阻塞队列是空的时候 向里面获取元素会被阻塞
 * 当阻塞队列是满的时候 向里面插入元素会被阻塞
 * 阻塞队列
 */
public class BlockingQueueDemo {
    public static void main(String[] args) throws InterruptedException {
        BlockingQueue<String> blockingQueue=new ArrayBlockingQueue<>(3);
//        blockingQueue.add("A");
//        blockingQueue.add("B");
//        blockingQueue.add("C");
//        System.out.println(blockingQueue.offer("A")); ;
//        System.out.println(blockingQueue.offer("B")); ;
//        System.out.println(blockingQueue.offer("C")); ;
//        System.out.println(blockingQueue.offer("D")); ;
//
//        System.out.println(blockingQueue.peek()); ;
//        System.out.println(blockingQueue.poll()); ;
//        System.out.println(blockingQueue.poll()); ;
//        System.out.println(blockingQueue.poll()); ;
        blockingQueue.put("A");
        blockingQueue.put("B");
        blockingQueue.put("C");
        blockingQueue.put("D");

        blockingQueue.take();
        blockingQueue.take();
        blockingQueue.take();
    }
}
